


const url = require('url');
let App = null;

function Login(app)
{
    App = app;
    //不用写具体路径，主js直接转过来了
    App.get('/login', (req, res) => {
        var string = url.parse(req.url, true);
        //解析参数
        var params = url.parse(req.url, true).query;
        console.log(params);
        var user = {};
        user.name = params.name;
        user.pwd = params.pwd;
        var responseJson = { name: 'abc', pwd: '123' };
        var response = { status: 11, data: user };
        // res.send(JSON.stringify(response));
        console.log("URL:" + req.url + "  " + string.pathname);
        res.status(200).json(response);
        //有数据返回用res.send();
        //无数据返回用res.end();
        // res.end("hello nodejs");

        //情况控制台日志
    });


    App.get('/logout', (req, res) => {
        var string = url.parse(req.url, true);
        //解析参数
        var params = url.parse(req.url, true).query;
        console.log(params);
        var user = {};
        user.name = params.name;
        user.token = params.token;
        var responseJson = { name: 'abc' };
        var response = { status: 2, data: user };
        // res.send(JSON.stringify(response));
        console.log("URL:" + req.url + "  " + string.pathname);
        res.status(200).json(response);
        //有数据返回用res.send();
        //无数据返回用res.end();
        // res.end("hello nodejs");
        res.end()
    });
}


//少了这句 报错：TypeError: Router.use() requires a middleware function but got a Object
module.exports = Login;

// 在主js里面
// app.use(’/run’,require(’./run.js’));
// //模块 run.js
// //接口文件需要引用路由模块
// router=express.Router();
// router.get(’/’,function(){…})//自动拼接。。实际访问接口就是/run/接口
// router.get(’/one’,function(){…})//这个就/runt/one接口
// module.exports = router; （少了这句会出现下面的错误）
// TypeError: Router.use() requires a middleware function but got a Object
